"""
from http://code.activestate.com/recipes/190465/
"""

from __future__ import generators

def xcombinations(items, n):
    if n==0: yield []
    else:
        for i in xrange(len(items)):
            for cc in xcombinations(items[:i]+items[i+1:],n-1):
                yield [items[i]]+cc


def permutations(items):
    return xcombinations(items, len(items))


if __name__=="__main__":
	
    import sys
    elements =  range(0,int(sys.argv[1])) 		
    json = """{"array_of_perms":["""	
    for c in xcombinations(elements, len(elements)): json += ''.join(str(c)) + ","
    json += "]}"

    print json.replace(",]", "]")
    
